<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\assets\TableAsset;
use app\models\KeyMap;
use app\models\Agent;
use app\models\UserCardRecharge;
use app\widgets\LinkPager;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use dosamigos\datepicker\DatePicker;
/**
 * @var $this yii\web\View
 * @var $rechargeList app\models\UserCardRecharge[]
 * @var $pagination yii\data\Pagination
 */

ApiAsset::register($this);
LayerAsset::register($this);
TableAsset::register($this);

$this->title = '卡充值列表';
$this->params['breadcrumbs'][] = '财务管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <label for="search_iccid" class="sr-only">ICCID</label>
    <?php echo Html::textInput('search_iccid', Yii::$app->request->get('search_iccid'), ['id'=>'search_iccid', 'class'=>'form-control', 'placeholder'=>'ICCID', 'style' => 'min-width:180px;']);?>
</div>
<div class="form-group">
    <label for="search_trade_no" class="sr-only">Trade_no</label>
    <?php echo Html::textInput('search_trade_no', Yii::$app->request->get('search_trade_no'), ['id'=>'search_trade_no', 'class'=>'form-control', 'placeholder'=>'交易编号', 'style' => 'width:180px;']);?>
</div>
<?php if (!empty($agent_id)) {?>
<div class="form-group">
    <label for="search_api_id" class="sr-only">下级代理商</label>
    <?php 
    $searchAgent = Agent::find()->andWhere(['id' => $agent])->one();
    $agentIdList = [$searchAgent->id];
    $agentIdList = array_merge($agentIdList, $searchAgent->getSubAidList());
    echo Html::dropDownList('search_agent_id', Yii::$app->request->get('search_agent_id'), ArrayHelper::map(Agent::find()->andWhere(['id' => $agentIdList])->andWhere(['not in','id',$agent])->all(), 'id', 'username'), ['id'=>'search_agent_id', 'class'=>'form-control', 'prompt'=>'下级代理商']);?>
</div>
<?php }?>
<div class="form-group">
    <label for="search_recharge_type" class="sr-only">充值状态</label>
    <?php echo Html::dropDownList('search_recharge_type', Yii::$app->request->get('search_recharge_type'), KeyMap::getValues('recharge_type'), ['id' => 'search_recharge_type', 'class' => 'form-control', 'prompt' => '充值状态']);?>
</div>
<div class="form-group">
    <label for="time">起始时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_start_time', 
        'options' => ['placeholder' => '时间'], 
        'attribute' => 'time',
        'template' => '{addon}{input}',
        'value' => $search_start_time,
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>
</div>
<div class="form-group">
    <label for="time">结束时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_end_time', 
        'options' => ['placeholder' => '时间'], 
        'attribute' => 'time',
        'template' => '{addon}{input}',
        'value' => $search_end_time,
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
    <a href="<?php echo Url::current(['export'=>'excel']);?>">导出Excel</a>
    <a href="<?php echo Url::current(['export'=>'csv']);?>">导出CSV</a>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th class="center">
            <label class="pos-rel">
                <span class="lbl">编号</span>
            </label>
        </th>
        <th class="center">代理商</th>
        <th class="center">ICCID</th>
        <th class="center">套餐</th>
        <th class="center">充值时长</th>
        <th class="center">充值状态</th>
        <th class="center">成本价</th>
        <th class="center">销售价</th>
        <th class="center">交易号</th>
        <th class="center">支付时间</th>
        <th class="center">操作</th>
    </tr>
    </thead>

    <tbody>
    <?php foreach ($rechargeList as $recharge) {?>
        <tr>
            <td class="center"><label class="pos-rel"><span class="lbl"><?php echo $recharge->id;?></span></label></td>
            <td class="center"><?php echo empty($recharge->agent_id) ? '----' : Html::encode($recharge->agent->username);?></td>
            <td class="center"><?php echo empty($recharge->card->iccid) ? '----' : Html::encode($recharge->card->iccid);?></td>
            <td class="center"><?php echo Html::encode($recharge->package->name);?></td>
            <td class="center"><?php echo $recharge->term_length, KeyMap::getValue('card_term_length_unit', $recharge->term_length_unit);?></td>
            <td class="center">
                <?php echo empty($recharge->recharge_type)?'----':Html::encode(KeyMap::getValue('recharge_type',$recharge->recharge_type));?>
            </td>
            <td class="center"><?php echo $recharge->packages->cost_price;?></td>
            <td class="center"><?php echo $recharge->packages->sale_price;?></td>
            <td class="center"><?php echo Html::encode($recharge->trade_no), '<br />', Html::encode($recharge->trans_id);?></td>
            <td class="center"><?php echo Yii::$app->formatter->asDatetime($recharge->pay_time);?></td>
            <td class="center"><?php echo ManagerTableOp::widget(['items' => [
                    ['icon' => 'fa fa-info-circle', 'href' => Url::to(['/agent/profit/recharge-view', 'id' => $recharge->id]), 'btn_class' => 'btn btn-xs btn-default', 'tip' => '详情'],
                    
                ]]);?>
            </td>
        </tr>
    <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>

